#include <iostream>
#include <thread>
#include <future>

// promise对象的学习使用

void Add(int num1, int num2, std::promise<int> &pro)
{
    std::cout << "加法！\n";
    pro.set_value(num1 + num2);
    return ;
}

int main()
{
    std::promise<int> pro;
    std::future<int> fut = pro.get_future();
    std::thread thread1(Add, 11, 22, std::ref(pro)); // ref设置为通过引用传递该参数
    int ret = fut.get();
    std::cout << "sum: " << ret << std::endl;
    thread1.join();
    return 0;
}